#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <fcntl.h>

int main()
{
  int pipefd[2] = {0}; // 0 read, 1 write 
  if(pipe(pipefd) < 0){
    perror("pipe");
    return 1;
  }
  //printf("pipefd[0]:%d\n", pipefd[0]);//查看fd
  //printf("pipefd[0]:%d\n", pipefd[0]);
  int ret = 0;
  int count  = 0;
  int flags = fcntl(pipefd[1], F_GETFL);// 获取文件状态标志
  fcntl(pipefd[1], F_SETFL, flags | O_NONBLOCK);//F_SETFL设置文件状态标志，//阻塞式等待
  while(1){
    ret = write(pipefd[1], "a", 1);
    if(ret < 0){
      perror("write");
      break;
    }
    count++;
  }
  printf("size = %d\n", count);
  return 0;
}
